home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / djfield / djfield.ctl (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-21  |  10.4 KB  |  297 lines

  1. VERSION 5.00
  2. Begin VB.UserControl DJField 
  3.    ClientHeight    =   390
  4.    ClientLeft      =   0
  5.    ClientTop       =   0
  6.    ClientWidth     =   1395
  7.    ScaleHeight     =   390
  8.    ScaleWidth      =   1395
  9.    Begin VB.TextBox Text1 
  10.       BeginProperty Font 
  11.          Name            =   "MS Sans Serif"
  12.          Size            =   9.75
  13.          Charset         =   0
  14.          Weight          =   400
  15.          Underline       =   0   'False
  16.          Italic          =   0   'False
  17.          Strikethrough   =   0   'False
  18.       EndProperty
  19.       Height          =   315
  20.       Left            =   45
  21.       TabIndex        =   0
  22.       Text            =   "Text1"
  23.       Top             =   30
  24.       Width           =   1215
  25.    End
  26. Attribute VB_Name = "DJField"
  27. Attribute VB_GlobalNameSpace = False
  28. Attribute VB_Creatable = True
  29. Attribute VB_PredeclaredId = False
  30. Attribute VB_Exposed = True
  31. 'This is an example control project of using a vtable binding class
  32. 'to improve execution speed. See test form in project1 for speed
  33. 'testing procedure. This is a case where the enumerated data type (vForceCase)
  34. 'does not cause an error.
  35. Implements iFastField
  36. Option Explicit
  37. Private m_Text As String
  38. Private m_Size As Integer
  39. Private m_ForceNumeric As Boolean
  40. Private m_ForceCase As vForceCase
  41. Private m_ForceString As String
  42. Private m_LastKey As String
  43. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
  44.     (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  45. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
  46.     (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  47. Private Const GWL_STYLE = (-16)
  48. Enum vForceCase
  49.   [Default] = 0
  50.   [Upper Case] = 1
  51.   [Lower Case] = 2
  52. End Enum
  53. 'Event Declarations:
  54. Event KeyPress(KeyAscii As Integer) 'MappingInfo=Text1,Text1,-1,KeyPress
  55. Attribute KeyPress.VB_Description = "Occurs when the user presses and releases an ANSI key."
  56. Private Sub Text1_Change()
  57.   If Len(m_ForceString) > 0 Then
  58.     If InStr((LCase(m_ForceString) & vbBack & vbNullString & vbCr), LCase(m_LastKey)) = 0 Then
  59.       Text = m_Text
  60.       Text1.SelStart = m_Size
  61.       Exit Sub
  62.     End If
  63.   End If
  64.   If Len(Text1) > m_Size Then
  65.     Text = m_Text
  66.     Text1.SelStart = m_Size
  67.     Exit Sub
  68.   End If
  69.   m_Text = Text1
  70. End Sub
  71. Private Sub Text1_KeyPress(KeyAscii As Integer)
  72.   m_LastKey = Chr(KeyAscii)
  73.   RaiseEvent KeyPress(KeyAscii)
  74. End Sub
  75. Public Property Get Size() As Integer
  76.   Size = m_Size
  77. End Property
  78. Public Property Let Size(ByVal New_Size As Integer)
  79.   m_Size = New_Size
  80. End Property
  81. Public Property Get Text() As String
  82. Attribute Text.VB_UserMemId = 0
  83. Attribute Text.VB_MemberFlags = "200"
  84.   Text = m_Text
  85. End Property
  86. Public Property Let Text(ByVal New_text As String)
  87.   Text1 = New_text
  88.   m_Text = New_text
  89. End Property
  90. Private Sub Text1_GotFocus()
  91.   Text1.SelStart = Len(Text1)
  92. End Sub
  93. Private Sub UserControl_InitProperties()
  94.   m_Size = Len(Extender.Name)
  95.   Me.Text = Extender.Name
  96. End Sub
  97. Private Sub UserControl_Resize()
  98.   With UserControl
  99.     Text1.Move 0, 0, .ScaleWidth, .ScaleHeight
  100.   End With
  101. End Sub
  102. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  103.   With PropBag
  104.     ForceString = .ReadProperty("ForceString", vbNullString)
  105.     ForceNumeric = .ReadProperty("ForceNumeric", False)
  106.     ForceCase = .ReadProperty("ForceCase", [Default])
  107.     Size = .ReadProperty("Size", Len(Extender.Name))
  108.     Text = .ReadProperty("Text", Extender.Name)
  109.     SelLength = .ReadProperty("SelLength", 0)
  110.     SelStart = .ReadProperty("SelStart", 0)
  111.     SelText = .ReadProperty("SelText", "")
  112.     Locked = .ReadProperty("Locked", False)
  113.     Enabled = .ReadProperty("Enabled", True)
  114.   End With
  115. End Sub
  116. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  117.   With PropBag
  118.     Call .WriteProperty("ForceString", m_ForceString, vbNullString)
  119.     Call .WriteProperty("ForceCase", m_ForceCase, [Default])
  120.     Call .WriteProperty("ForceNumeric", m_ForceNumeric, False)
  121.     Call .WriteProperty("Text", m_Text)
  122.     Call .WriteProperty("Size", m_Size)
  123.     Call .WriteProperty("SelLength", Text1.SelLength, 0)
  124.     Call .WriteProperty("SelStart", Text1.SelStart, 0)
  125.     Call .WriteProperty("SelText", Text1.SelText, "")
  126.     Call .WriteProperty("Locked", Text1.Locked, False)
  127.     Call .WriteProperty("Enabled", Text1.Enabled, True)
  128.  End With
  129. End Sub
  130. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  131. 'MappingInfo=Text1,Text1,-1,SelLength
  132. Public Property Get SelLength() As Long
  133. Attribute SelLength.VB_Description = "Returns/sets the number of characters selected."
  134.   SelLength = Text1.SelLength
  135. End Property
  136. Public Property Let SelLength(ByVal New_SelLength As Long)
  137.   Text1.SelLength() = New_SelLength
  138.   PropertyChanged "SelLength"
  139. End Property
  140. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  141. 'MappingInfo=Text1,Text1,-1,SelStart
  142. Public Property Get SelStart() As Long
  143. Attribute SelStart.VB_Description = "Returns/sets the starting point of text selected."
  144.   SelStart = Text1.SelStart
  145. End Property
  146. Public Property Let SelStart(ByVal New_SelStart As Long)
  147.   Text1.SelStart() = New_SelStart
  148.   PropertyChanged "SelStart"
  149. End Property
  150. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  151. 'MappingInfo=Text1,Text1,-1,SelText
  152. Public Property Get SelText() As String
  153. Attribute SelText.VB_Description = "Returns/sets the string containing the currently selected text."
  154.   SelText = Text1.SelText
  155. End Property
  156. Public Property Let SelText(ByVal New_SelText As String)
  157.   Text1.SelText() = New_SelText
  158.   PropertyChanged "SelText"
  159. End Property
  160. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  161. 'MappingInfo=Text1,Text1,-1,Locked
  162. Public Property Get Locked() As Boolean
  163. Attribute Locked.VB_Description = "Determines whether a control can be edited."
  164.   Locked = Text1.Locked
  165. End Property
  166. Public Property Let Locked(ByVal New_Locked As Boolean)
  167.   Text1.Locked() = New_Locked
  168.   PropertyChanged "Locked"
  169. End Property
  170. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  171. 'MappingInfo=UserControl,UserControl,-1,hWnd
  172. Public Property Get hWnd() As Long
  173. Attribute hWnd.VB_Description = "Returns a handle (from Microsoft Windows) to an object's window."
  174.   hWnd = UserControl.hWnd
  175. End Property
  176. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  177. 'MappingInfo=Text1,Text1,-1,Enabled
  178. Public Property Get Enabled() As Boolean
  179. Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
  180.   Enabled = Text1.Enabled
  181. End Property
  182. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  183.   Text1.Enabled() = New_Enabled
  184.   PropertyChanged "Enabled"
  185. End Property
  186. Public Property Get ForceNumeric() As Boolean
  187.   ForceNumeric = m_ForceNumeric
  188. End Property
  189. Public Property Let ForceNumeric(ByVal Force As Boolean)
  190.   Dim style As Long
  191.   Const ES_NUMBER = &H2000
  192.   m_ForceNumeric = Force
  193.   ' get current style
  194.   style = GetWindowLong(Text1.hWnd, GWL_STYLE)
  195.   If Force Then
  196.       style = style Or ES_NUMBER
  197.   Else
  198.       style = style And Not ES_NUMBER
  199.   End If
  200.   ' enforce new style
  201.   SetWindowLong Text1.hWnd, GWL_STYLE, style
  202.   PropertyChanged "ForceNumeric"
  203. End Property
  204. Public Property Get ForceCase() As vForceCase
  205.   ForceCase = m_ForceCase
  206. End Property
  207. Public Property Let ForceCase(ByVal New_Case As vForceCase)
  208.   Dim style As Long
  209.   If m_ForceNumeric Then ForceNumeric = False
  210.   Const ES_UPPERCASE = &H8&
  211.   Const ES_LOWERCASE = &H10&
  212.   m_ForceCase = New_Case
  213.   ' get current style
  214.   style = GetWindowLong(Text1.hWnd, GWL_STYLE)
  215.   Select Case New_Case
  216.     Case [Default]
  217.       style = style And Not (ES_UPPERCASE Or ES_LOWERCASE)
  218.     Case [Upper Case]
  219.       style = style Or ES_UPPERCASE
  220.     Case [Lower Case]
  221.       style = style Or ES_LOWERCASE
  222.   End Select
  223.   ' enforce new style
  224.   SetWindowLong Text1.hWnd, GWL_STYLE, style
  225.   PropertyChanged "ForceCase"
  226. End Property
  227. Public Property Get ForceString() As String
  228.   ForceString = m_ForceString
  229. End Property
  230. Public Property Let ForceString(ByVal New_String As String)
  231.   m_ForceString = New_String
  232.   PropertyChanged "ForceString"
  233. End Property
  234. Private Property Let iFastField_Enabled(ByVal New_Enabled As Boolean)
  235.   Enabled = New_Enabled
  236. End Property
  237. Private Property Get iFastField_Enabled() As Boolean
  238.   iFastField_Enabled = Enabled
  239. End Property
  240. Private Property Let iFastField_ForceCase(ByVal New_Case As vForceCase)
  241.   ForceCase = New_Case
  242. End Property
  243. Private Property Get iFastField_ForceCase() As vForceCase
  244.   iFastField_ForceCase = ForceCase
  245. End Property
  246. Private Property Let iFastField_ForceNumeric(ByVal Force As Boolean)
  247.   ForceNumeric = Force
  248. End Property
  249. Private Property Get iFastField_ForceNumeric() As Boolean
  250.   iFastField_ForceNumeric = ForceNumeric
  251. End Property
  252. Private Property Let iFastField_ForceString(ByVal New_String As String)
  253.   ForceString = New_String
  254. End Property
  255. Private Property Get iFastField_ForceString() As String
  256.   iFastField_ForceString = ForceString
  257. End Property
  258. Private Property Get iFastField_hWnd() As Long
  259.   iFastField_hWnd = hWnd
  260. End Property
  261. Private Property Let iFastField_Locked(ByVal New_Locked As Boolean)
  262.   Locked = New_Locked
  263. End Property
  264. Private Property Get iFastField_Locked() As Boolean
  265.   iFastField_Locked = Locked
  266. End Property
  267. Private Property Let iFastField_SelLength(ByVal New_SelLength As Long)
  268.   SelLength = New_SelLength
  269. End Property
  270. Private Property Get iFastField_SelLength() As Long
  271.   iFastField_SelLength = SelLength
  272. End Property
  273. Private Property Let iFastField_SelStart(ByVal New_SelStart As Long)
  274.   SelStart = New_SelStart
  275. End Property
  276. Private Property Get iFastField_SelStart() As Long
  277.   iFastField_SelStart = SelStart
  278. End Property
  279. Private Property Let iFastField_SelText(ByVal New_SelText As String)
  280.   SelText = New_SelText
  281. End Property
  282. Private Property Get iFastField_SelText() As String
  283.   iFastField_SelText = SelText
  284. End Property
  285. Private Property Let iFastField_Size(ByVal New_Size As Integer)
  286.   Size = New_Size
  287. End Property
  288. Private Property Get iFastField_Size() As Integer
  289.   iFastField_Size = Size
  290. End Property
  291. Private Property Let iFastField_Text(ByVal New_text As String)
  292.   Text = New_text
  293. End Property
  294. Private Property Get iFastField_Text() As String
  295.   iFastField_Text = Text
  296. End Property
  297.